#include <iostream>  
using namespace std;  
  
//支持所有数据类型的函数模板
template <class T>  
inline T square(T x)  
{  
   T result;  
   result = x * x;  
   return result;  
};  

main()  
{  
   int    i, ii;  
   float  x, xx;  
   double y, yy;  
  
   i = 2;  
   x = 2.2;  
   y = 2.2;  
  
   ii = square<int>(i);  
   cout << i << ": " << ii << endl;  
  
   xx = square<float>(x);  
   cout << x << ": " << xx << endl;  
  
   // Explicit use of template  
   yy = square<double>(y);// 显式使用模板  
   cout << y << ": " << yy << endl;  
  
   yy = square(y);//隐含的方式使用模板  
   cout << y << ": " << yy << endl;  
}  